package main

import "fmt"

func main() {

	arr := [5]int{8, 1, 3, 6, 7}

	bubble_sort(&arr)

	fmt.Println(arr)
}

func bubble_sort(sort *[5]int) {
	len := len(*sort)
	fmt.Println(sort)

	exchange := false

	count := new(int)

	for i := 0; i < len-1; i++ {
		exchange = false
		for j := 0; j < len-1-i; j++ {
			if sort[j] > sort[j+1] {
				sort[j], sort[j+1] = sort[j+1], sort[j]
				exchange = true
			}

			*count++
		}

		if !exchange {
			fmt.Printf("count = %d \n", *count)
			return
		}
	}

}
